<?php

/* @var $this yii\web\View */

use yii\helpers\Html;

$this->title = 'Unix时间戳';
$this->params['breadcrumbs'][] = $this->title;

$js = <<<JS
	
	$('.submit').click(function(){

		var that = $(this);
		var item = that.attr('id');

		var input = 'item='+item;
		if (item == 'unixToDate') {
			input += '&unixTime=' + $('input[name=unixTime]').val();
			input += '&type=' + $('select option:selected').val();
		} else if (item == 'dateToUnix') {
			input += '&date=' + $('input[name=date]').val();
		}

		$.post('/utils/do', {input:input}, function(rs){
			if (rs.errno != 0) {
				alert(rs.error);
			}

			if (rs.data.length != 0) {
				that.parents('li').find('code').empty().text(rs.data);
			}
		},'json');
	});

JS;
$this->registerJs($js);

$css = <<<CSS
	input, select{
		width: 150px;
		height:26px;
		line-height: 26px;
	}

	select {
		width: 60px;
	}

CSS;
$this->registerCss($css);

?>
<div class="site-index scene">
	<ul>
		<li>
			<p>1.当时时间戳 <button id="timeStamp" class="submit">刷新时间戳</button></p>
			<code><?= time();?></code>
		</li>

		<li>
			<p>
				2.Unix时间戳：
				<input type="text" name="unixTime" placeholder="填写Unix时间戳">
				<select name="type">
					<option value='0'>秒</option>
					<option value='1'>毫秒</option>
				</select>
				<button id="unixToDate" class="submit">转换成北京时间</button>
			</p>
			<code><?= date('Y-m-d H:i:s')?></code>
		</li>

		<li>
			<p>
				3.日期转时间Unix戳：
				<input type="text" name="date" placeholder="填写日期">
				<button id="dateToUnix" class="submit">转换成时间戳</button>
			</p>
			<code></code>
		</li>
	</ul>
</div>